package jnzb.nzb;

import java.util.Iterator;
import java.util.List;

/**
 * NZB file element
 * 
 * @author AA1
 * 
 */
public class File {

	// Attributes
	private String poster;
	private int date;
	private String subject;

	// Children

	public String getPoster() {
		return poster;
	}

	public void setPoster(String poster) {
		this.poster = poster;
	}

	public int getDate() {
		return date;
	}

	public void setDate(int date) {
		this.date = date;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public List<String> getGroups() {
		return groups;
	}

	public void setGroups(List<String> groups) {
		this.groups = groups;
	}

	public List<Segment> getSegments() {
		return segments;
	}

	public void setSegments(List<Segment> segments) {
		this.segments = segments;
	}

	// This is a shortcut - should be 1 groups element containing multiple
	// groups, but whats the point?
	private List<String> groups;

	// Another shortcut - should be a segments element with lots of segment in
	private List<Segment> segments;

	public int getNumberOfGroups(){
		return this.groups.size();
	}
	
	public int getNumberOfSegments(){
		return this.segments.size();
	}
	
	/**
	 * @return true if all segments for this file have been downloaded
	 */
	public boolean allSegmentsDownloaded(){
		Iterator<Segment> i = segments.iterator();
		
		boolean allDownloaded=true;
		while (i.hasNext()){
			allDownloaded|=i.next().hasBeenDownloaded();
		}
		return allDownloaded;
	}
}
